﻿using Pay.Dal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pay.Model.Model;
using Pay.Dapper;
using Dapper.Contrib.Extensions;
using Dapper;
namespace Pay.DalImplement
{
  public   class AliOrderDalImplement: IAliOrderDal
    {
        /// <summary>
        /// 获取order 根据金额与备注
        /// </summary>
        /// <param name="amount"></param>
        /// <param name="des"></param>
        /// <returns></returns>
        public async Task<AliOrderInfo> GetOrder(decimal amount, string des)
        {

            using (var conn = ConnectionFactory.GetWriteConnection())
            {
                string sql = "SELECT top 1 [Id],[TradeTitle],[AliOrderNo],[AliTradeNo],[ToAccount],[Amount],[Des],[Status],[CreateTime],[SysTime] FROM aliorder_info where Amount=@Amount and Des=@Des order by CreateTime desc";

              return await  conn.QueryFirstAsync<AliOrderInfo>(sql, new { Des = des, Amount = amount });
            }
        }

        public async Task<long> Add(AliOrderInfo model)
        {
            using (var conn = ConnectionFactory.GetWriteConnection())
            {
                return await conn.InsertAsync<AliOrderInfo>(model);
            }
        }
    }
}
